<?php 
	/**
	 * 主程序，每日抓取最新数据，并提取和入库
	 */
	include_once dirname(dirname(__FILE__))."/include/common.inc.php";
	include_once dirname(dirname(__FILE__))."/zhenai/function.zhenai.php";
	$global_site = "zhenai";
	
	//抓取日期，默认为昨天
	$ymd =  date("Y-m-d", time()-60*60*24);
	if ($argc > 1) {
		$ymd = date("Y-m-d", strtotime($argv[1]));
	}
	
	//是否删除数据库中已经存在的数据
	if($argc > 2 && $argv[2] == "DELETE"){
		global $conn;
		$tblName = getTblname($ymd);
		$sql = "delete from $tblName where `from`='zhenai' and fetch_date='$ymd' ";
		$conn->query($sql);
	}
	
	$minId = getzhenaiMinId($ymd);
	$maxId = getzhenaiMaxId($ymd);
	$maxIdFinished = getzhenaiMaxIdFinished($ymd);
	printlog("yesterday min uid: $minId / max uid: $maxId / finished uid: $maxIdFinished", "main");
	$minId = ($maxIdFinished > $minId) ? $maxIdFinished : $minId; 
	echo $minId.'----'.$maxIdFinished.'--------'.$maxId;
	
	//抓取，提取和入库
	/*
	$uid = 83738531;
	$page = file_get_contents($uid.'.html');
	doWithzhenaiPage($uid, $ymd, $page);
	exit;
	*/
	
	zhenai_data($minId, $maxId, $ymd);	
	

?>